<template>
	<view class="viewcontent">
		<view class="viewcontenthead">
			<view class="fl" @click="$UTILS.goBack(1)"></view>
			<view class="fr" style="color: #fdf5fa;"> 离线导入</view>
			<view class="leftitem">
			</view>
		</view>
		<view class="content">
			<view class="text">
				<!-- <uni-easyinput v-model="value" placeholder="请输入文件夹路径,并保证仅存一个json文件" @input="input"></uni-easyinput> -->
				<view v-for="(item,index) in inputtaskcopy" :key="index">
				{{item}}
				</view>
			</view>
			<view class="btn_st">
				<u-button @click="dialogToggle">获取任务</u-button>
			</view>
			<view class="btn_st">
				<u-button @click="getequipmentcode">获取设备</u-button>
			</view>
		</view>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog type="info" cancelText="否" confirmText="是" title="通知" content="是否引入本地任务？"
				@confirm="dialogConfirm" @close="dialogClose">
				</uni-popup-dialog>
		</uni-popup>
		<uni-popup ref="alertDialogequipmentcode" type="dialog">
			<uni-popup-dialog type="info" cancelText="否" confirmText="是" title="通知" content="是否引入本地设备？"
				@confirm="dialogConfirmequipmentcode" @close="dialogCloseequipmentcode">
				</uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value: '',
				inputtask: [],
				inputpath: '',
				inputtaskcopy: [],
				inpequipmentcode:[]
			};
		},
		onShow() {
			this.inputtaskcopy = uni.getStorageSync("tasklocal");
			console.log('load获取', this.inputtaskcopy)
		},
		methods: {
			dialogCloseequipmentcode(){
				
			},
			dialogConfirmequipmentcode(){
				this.getEquiment()
			},
			getequipmentcode(){
				this.$refs.alertDialogequipmentcode.open()
			},
			dialogClose(){
				
			},
			dialogConfirm(){
				this.getTask()
			},
			dialogToggle(){
				this.$refs.alertDialog.open()
			},
			getEquiment() {
			
				plus.io.requestFileSystem(
					plus.io.PUBLIC_DOWNLOADS,
					fs => {
						fs.root.getFile('equipmentcode.json', {
							create: true
						}, fileEntry => {
							fileEntry.file(function(file) {
								var fileReader = new plus.io.FileReader();
								console.log("getFile:" + JSON.stringify(file));
								fileReader.readAsText(file, "utf-8")
								fileReader.onloadend = function(res) {
									let demo = JSON.parse(res.target.result);
									this.inpequipmentcode = demo.result?.records
									// this.$UTILS.setloceq(this.inpequipmentcode)
									uni.setStorage({
									    key: 'loceq',
									    data: JSON.stringify(this.inpequipmentcode) 
									})
									
									console.log(this.$UTILS.getloceq())
									this.$UTILS.toast('获取成功')
								}
							});
						}, e => {
							console.log('报错111', "getFile failed: " + e.message);
						});
					},
			
					e => {
						console.log('报错222', e.message);
					}
				);
			},
			getTask() {

				plus.io.requestFileSystem(
					plus.io.PUBLIC_DOWNLOADS,
					fs => {
						fs.root.getFile('task.json', {
							create: true
						}, fileEntry => {
							this.inputpath = fileEntry.fullPath
							console.log('文件在手机中的路径', fileEntry.fullPath)
							fileEntry.file(function(file) {
								var fileReader = new plus.io.FileReader();
								console.log("getFile:" + JSON.stringify(file));
								fileReader.readAsText(file, "utf-8")
								fileReader.onloadend = function(res) {
									let demo = JSON.parse(res.target.result);
									this.inputtask = demo.result
									// this.$UTILS.setitemlist( this.inputtask)
									uni.setStorage({
									    key: 'itemlist',
									    data: this.inputtask
									})
									this.$UTILS.toast('获取成功')

								}
							});
						}, e => {
							console.log('报错111', "getFile failed: " + e.message);
						});
					},

					e => {
						console.log('报错222', e.message);
					}
				);
			},
			input(e) {
				this.value = e
			},
		}
	}
</script>

<style lang="scss">
	.viewcontent {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 100vh;
		box-sizing: border-box;
		padding-top: 55rpx;

		.viewcontenthead {
			width: 100%;
			height: 5%;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.fl {
				width: 100rpx;
				height: 10vh;
				line-height: 10vh;
				background: url("/static/right-arrow.png") no-repeat center;
				background-size: 14%;
				transform: rotate(180deg);
				cursor: pointer; // 增加鼠标指针样式
			}

			.fr {
				cursor: pointer; // 增加鼠标指针样式
			}

			.leftitem {
				width: 100rpx;
				display: flex;
				justify-content: center;
				z-index: 999;
			}
		}

		.content {
			width: 100%;
			height: 95%;
			box-sizing: border-box;
			padding: 25px 10px;

			.text {
				width: 100%;
				height: 500px;
				color: white;
				overflow: auto;
			}
		}

		.btn_st {
			margin-top: 15px;
		}

	}

	/deep/ .uni-input-input {
		color: white;
	}
</style>